//
//  MoreDoctorViewController.m
//  EcmDoctor
//
//  Created by Mac on 16/2/22.
//  Copyright © 2016年 张进. All rights reserved.
//

#import "MoreDoctorViewController.h"
#import "MoreDoctorTableViewCell.h"
#import "AppUtils.h"
#import "MoreDoctorList.h"
#import "UIImageView+AFNetworking.h"
@interface MoreDoctorViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    
    __weak IBOutlet UITableView *_moreDoctorTv;
    NSMutableArray *_dataAry;
}
@end

@implementation MoreDoctorViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;

    self.navigationItem.titleView=[AppUtils generateNavigationItemTitleViewWithTitle:@"更多医生"];
    //左上角返回按钮
    UIImage *tableIcon = [UIImage imageNamed:@"btn_back"];
    self.navigationItem.leftBarButtonItem =[[UIBarButtonItem alloc] initWithImage:tableIcon style:UIBarButtonItemStylePlain target:self action:@selector(changeToNavRootController:)];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithPatternImage:tableIcon];
    self.view.backgroundColor = [AppUtils getBackground];
    _moreDoctorTv.rowHeight=100;
    [MoreDoctorList getMoreDoctorWith:@"1" success:^(NSMutableArray *doctorlistAry) {
        
      
        _dataAry=[NSMutableArray arrayWithArray:doctorlistAry];
        [_moreDoctorTv reloadData];
    } failure:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
}
-(void)changeToNavRootController:(id)sender{
    [self.navigationController popViewControllerAnimated:YES];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _dataAry.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell;
    
    MoreDoctorTableViewCell* moreDoctorCell = [tableView dequeueReusableCellWithIdentifier:@"moredoctor"forIndexPath:indexPath];
    
    MoreDoctorList *doclist=_dataAry[indexPath.row];
    moreDoctorCell.doctorHospital.text=doclist.office_hospital;
    
    
    UIFont *font = [UIFont systemFontOfSize:17.0];
 
    NSDictionary *fontDic = @{NSFontAttributeName:font};
    //frame->CGRect->size
    CGRect labelRect = [doclist.name boundingRectWithSize:CGSizeMake(MAXFLOAT,21) options:NSStringDrawingUsesLineFragmentOrigin attributes:fontDic context:nil];
    CGSize size = labelRect.size;
    moreDoctorCell.doctorName.font = font;
    moreDoctorCell.width.constant=size.width;
    moreDoctorCell.doctorName.text=doclist.name;
 
    moreDoctorCell.doctorPosition.text=doclist.job_position;
   
    [moreDoctorCell.doctorIcon setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://ecm-user.oss-cn-beijing.aliyuncs.com/image/%@",doclist.doctor_icon]] placeholderImage:[UIImage imageNamed:@"icon"]];
    cell=moreDoctorCell;
    return cell;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
        
        //需要注意的是self.isViewLoaded是必不可少的，其他方式访问视图会导致它加载 ，在WWDC视频也忽视这一点。
        
        if (self.isViewLoaded && !self.view.window)// 是否是正在使用的视图
        {
            // Add code to preserve data stored in the views that might be
            // needed later.
            
            // Add code to clean up other strong references to the view in
            // the view hierarchy.
            self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
        }
        
    }
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
